Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
nedb-promises
Advanced tools
A dead-simple promise wrapper for nedb.
Check out the docs.
As of nedb-promises
5.0.0
nedb package has been replaced with a fork of the original package, @seald-io/nedb to solve some vulnerability issues originating from nedb
!
const Datastore = require('nedb-promises')
let datastore = Datastore.create('/path/to/db.db')
// #1
datastore.find({ field: true })
.then(...)
.catch(...)
// #2
datastore.find({ field: true })
.exec(...)
.then(...)
.catch(...)
// #1 and #2 are equivalent
datastore.findOne({ field: true })
.then(...)
.catch(...)
datastore.insert({ doc: 'yourdoc' })
.then(...)
.catch(...)
// or in an async function
async function findSorted(page, perPage = 10) {
return await datastore.find(...)
.sort(...)
.limit(perPage)
.skip(page * perPage)
}
npm install --save nedb-promises
Everything works as the original module, with a couple of exceptions:
loadDatabase
has been renamed to load
.projection
method has been renamed to project
.Datastore.create(...)
instead of new Datastore(...)
. This way you can access the original nedb properties, such as datastore.persistence
.Check out the original docs!
You don't need to call this as the module will automatically detect if the datastore has been loaded or not upon calling any other method.
const Datastore = require('nedb-promises')
let datastore = Datastore.create('/path/to/db.db')
datastore.load(...)
.then(...)
.catch(...)
These methods will return a Cursor object that works the same way it did before except when you call "exec" it takes no arguments and returns a Promise.
The cool thing about this implementation of the Cursor is that it behaves like a Promise. Meaning that you can await
it and you can call .then()
on it.
const Datastore = require('nedb-promises')
let datastore = Datastore.create('/path/to/db.db')
//outside Promise chain
datastore.find(...)
.then(...)
.catch(...)
//insinde Promise chain
datastore.insert(...)
.then(() => {
return datastore.find(...)
})
.then(
// use the retrieved documents
)
;(async () => {
await datastore.find(...).sort(...).limit()
})()
All the other methods will take the same arguments as they did before (except the callback) and will return a Promise.
Check out the docs.
FAQs
A dead-simple promise wrapper for nedb.
The npm package nedb-promises receives a total of 2,458 weekly downloads. As such, nedb-promises popularity was classified as popular.
We found that nedb-promises demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.